#!/bin/sh
# postrm script for openmediavault-git
#

set -e

. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions

OMV_GIT_AUTHZ=${OMV_GIT_AUTHZ:-"/etc/git/authz"}
OMV_GIT_CONFIG=${OMV_GIT_CONFIG:-"/etc/apache2/conf.d/omv-git"}


if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then

	[ -f ${OMV_GIT_CONFIG} ] && /bin/rm -f ${OMV_GIT_CONFIG}
	[ -f /etc/git/web.conf ] && /bin/rm -f /etc/git/web.conf

	# Clean up after authz_external.. it doesn't disable itself
	# on uninstallation. We have no choice but to disable it on our
	# uninstallation. Otherwise OMV may fail to start apache2 on
	# the next reboot / restart
	[ -f /etc/apache2/mods-enabled/authnz_external.load ] && [ ! -f /etc/apache2/mods-available/authnz_external.load ] && a2dismod authnz_external

	if [ "$1" = "purge" ]; then
	
		[ -f ${OMV_GIT_AUTHZ} ] && /bin/rm -f ${OMV_GIT_AUTHZ}
		
		# Check for XML config
    	if omv_config_exists "//services/git"; then
			xmlstarlet ed -P -L -d "//services/git" ${OMV_CONFIG_FILE}
		fi
					
	fi
fi


exit 0
